In [51]:
# Intialization for notebook use
%pylab inline
import sympy as sp
sp.init_printing(use_latex=True)
import ipywidgets as widgets
In [3]:
x_1, x_2 = sp.symbols('x_1 x_2') # indentify these as symbols
λ = sp.symbols('λ')
Consider the following 2nd order system (Mass-Damper-Spring):
$\ddot{x} + \dot{x} = 3x + x^2 = 0 \Longleftrightarrow \ddot{x} + c \dot{x} + f(x) = 0$
$c$ is the dampening force and $f(x)$ is the non-linear spring.
The system can be placed into the $\dot{\underline{x}} = \underline{f}(\underline{x})$ form:
$\begin{cases} \dot{x}_1 = x_2 \\ \dot{x}_2 = -3x_1 - x_1^2 - x_2 \end{cases}$
$\begin{cases} f_1(x_1, x_2) = 0 \\ f_2(x_2, x_2) = 0 \end{cases} \Rightarrow \begin{cases} x_2 && = 0 \\ -3x_1 - x_1^2 - x_2 && = 0 \, \Rightarrow \, -3x_1 - x_1^2 = 0 \end{cases}$
$\begin{cases} x_2 = 0 \\ x_1(-3 - x_1) = 0 \end{cases} \Rightarrow$ 2 equillibrium points $\Rightarrow \begin{cases} \underline{x}_1 = [0, 0]^T \\ \underline{x}_2 = [-3, 0]^T \end{cases}$
$\displaystyle\dot{\underline{x}} = \underline{f}(\underline{x}) \Rightarrow \approx \underline{f}(\underline{x}^*) + \left . \frac{\partial \underline{f}}{\partial \underline{x}} \right |_{\underline{x}^*} (\underline{x} - \underline{x}^*)$
$\displaystyle A = \left . \frac{\partial\underline{f}}{\partial\underline{x}} \right |_{\underline{x}_{1, \, 2}^*} = \begin{bmatrix} 0 && 1 \\ -3 - 2x_1 && -1 \end{bmatrix}_{\underline{x}_1^*, \, \underline{x}_2^*}$
We have the following system:
$\dot{\underline{x}} = A_1 \underline{x} \Rightarrow A_1 = \begin{bmatrix} 0 && 1 \\ -3 && -1 \end{bmatrix}$
Look for the behavior of the system near $\underline{x}_1 = \underline{0}$. e-value analysis:
$\det (A_1 - \lambda I) = \begin{vmatrix} -\lambda && 1 \\ -3 && -1 - \lambda \end{vmatrix} = \lambda \big(\lambda + 1\big) + 3 = 0$
$\Rightarrow \lambda^2 + \lambda + 3 = 0 \Rightarrow \lambda_{12} = -\frac{1}{2} \left( 1 \pm \sqrt{1 - 12}\right) = -\frac{1}{2} \left( 1 \pm \sqrt{11} j\right)$
We have the following system:
$\dot{\underline{x}} = A_2 \underline{x} \Rightarrow A_2 = \begin{bmatrix} 0 && 1 \\ 3 && -1 \end{bmatrix}$
Look for the behavior of the system near $\underline{x}_2 = \underline{0}$. e-value analysis:
$\left|(A - \lambda I ) \right| = \begin{vmatrix} -\lambda && 1 \\ 3 && -1 - \lambda \end{vmatrix} = 0$
$\Rightarrow \lambda \left(\lambda + 1 \right) - 3 = 0 \Rightarrow \, \lambda^2 + \lambda - 3 = 0$
$\lambda = -\frac{1}{2} \left ( 1 \pm \sqrt{1 + 12} \right) = - \frac{1}{2} \pm \frac{1}{2} \sqrt{13}$
Note that both solutions of $\lambda$ are REAL! Therefore:
$\begin{matrix} \lambda_1 = -\frac{1}{2} \left( 1 - \sqrt{13} \right ) > 0 \\ \lambda_2 = -\frac{1}{2} \left( 1 + \sqrt{13} \right ) < 0 \end{matrix} \Rightarrow \text{ Unstable } \Rightarrow \underline{\text{Saddle Point}}$
Compute the e-vectors $\underline{v}_1,\, \underline{v}_2$ to determine the direction of convergence
Given that:
$\begin{cases} \dot{x}_1 = f_1(x_1, x_2) = x_2 \\ \dot{x}_2 = f_2(x_2, x_2) = -3x_1 - x_1^2 - x_2 \end{cases}$
We can define two variables to these functions:
In [4]:
f_1 = x_2
f_2 = -3 * x_1 - x_1 ** 2 - x_2
We can solve the system of equations using the solve
function.
In [5]:
slns = sp.solve([f_1, f_2])
slns
Out[5]:
We get the same solutions that we found previously.
To linearize the system, we need to take the derivatives of each function with respect to $x_1$ and $x_2$. We'll compile this into a matrix A_1 like so:
In [6]:
A = sp.Matrix([[sp.diff(f_1, x_1), sp.diff(f_1, x_2)], [sp.diff(f_2, x_1), sp.diff(f_2, x_2)]])
A
Out[6]:
Now we let $\dot{\underline{x}} = A_1 \, \underline{x}$. Therefore A_1
would be:
In [7]:
A_1 = sp.Matrix([[0, 1], [-3, -1]])
A_1
Out[7]:
Next we find the determinate of $A_1 - \lambda I$
In [8]:
λ_fun = sp.det(A_1 - λ * sp.eye(2))
λ_fun
Out[8]:
In [9]:
sp.solve(λ_fun)
Out[9]:
In [47]:
import numpy as np
from matplotlib import pyplot as plt
x1, x2 = np.meshgrid(np.linspace(-.5, .5, 10), np.linspace(-.5, .5, 10))
x1dot = x2
x2dot = -3 * x1 - x1 ** 2 - x2
In [48]:
plt.figure()
plt.quiver(x1, x2, x1dot, x2dot)
plt.show()
In [58]:
@widgets.interact (
x_start=(-10.0, 10.0, 0.1),
x_stop=(-10.0, 10.0, 0.1),
y_start=(-10.0, 10.0, 0.1),
y_stop=(-10.0, 10.0, 0.1),
space=(10, 50)
)
def inter_plot(x_start, x_stop, y_start, y_stop, space):
x1, x2 = np.meshgrid(np.linspace(x_start, x_stop, space), np.linspace(y_start, y_stop, space))
x1dot = x2
x2dot = -3 * x1 - x1 ** 2 - x2
plt.figure()
plt.quiver(x1, x2, x1dot, x2dot)
plt.show()
In [ ]: